package org.jmh.gift.controller;

import org.jmh.gift.domain.PayOrder;
import org.jmh.gift.query.PayOrderQuery;
import org.jmh.gift.service.IPayOrderService;
import org.jmh.gift.util.AjaxResult;
import org.jmh.gift.util.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/payOrder")
public class PayOrderController {
    @Autowired
    public IPayOrderService payOrderService;


    /**
     * 保存和修改公用的
     * @param payOrder  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody PayOrder payOrder){

        if( payOrder.getId()!=null)
            payOrderService.updateById(payOrder);
        else
            payOrderService.insert(payOrder);
        return AjaxResult.success();

    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        payOrderService.deleteById(id);
        return AjaxResult.success();

    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id")Long id)
    {

        PayOrder payOrder = payOrderService.selectById(id);
        return AjaxResult.success(payOrder);

    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult list(){

        List< PayOrder> list = payOrderService.selectList(null);
        return AjaxResult.success(list);

    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult json(@RequestBody PayOrderQuery query)
    {
        Page<PayOrder> page = new Page<PayOrder>(query.getPage(),query.getRows());
        page = payOrderService.selectPage(page);
        PageList pageList = new PageList<PayOrder>(page.getTotal(),page.getRecords());
        return AjaxResult.success(pageList);
    }

    @PutMapping("/cancal/{uniPayOrderSn}")
    public AjaxResult cancelPayOrder(@PathVariable("uniPayOrderSn")String uniPayOrderSn){
        payOrderService.cancel(uniPayOrderSn);
        return AjaxResult.success();
    }
}
